Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4236] feat(core): Rework of post hook for dispatcher #4429

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

jerqi
Copy link
Contributor

@jerqi jerqi commented Aug 8, 2024

What changes were proposed in this pull request?

Rework of post hook for dispatcher .

  1. Implement a new class dispatcher instead dynamic proxy.
  2. Optimize the lock logic
  3. Add the securable object metalake back. We just remove the privileges of the metalake. We should remove the securable object metalake.

Why are the changes needed?

Fix: #4236

Does this PR introduce any user-facing change?

NO.

How was this patch tested?

Add new ITs.

@jerqi jerqi marked this pull request as draft August 8, 2024 02:59
@jerqi jerqi changed the title Add hook dispatcher [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher Aug 8, 2024
Comment on lines 66 to 82
for (CatalogCreatePostHook hook : createPostHooks) {
hook.execute(ident);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can directly execute the here, didn't need to call hook.execute().

        ownerManager.setOwner(
            ident.name(),
            NameIdentifierUtil.toMetadataObject(ident, Entity.EntityType.METALAKE),
            PrincipalUtils.getCurrentUserName(),
            Owner.Type.USER);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that we should extract the abstraction of the hook. It will be convenient to extend more post hooks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we didn't need this class.

@jerqi jerqi force-pushed the ISSUE-4236 branch 6 times, most recently from 5f296b0 to 4454e2b Compare August 8, 2024 09:09
@jerqi jerqi marked this pull request as ready for review August 8, 2024 09:12
@jerqi jerqi requested a review from xunliu August 8, 2024 09:13
@jerqi jerqi force-pushed the ISSUE-4236 branch 2 times, most recently from 79561de to 53aaa1a Compare August 8, 2024 09:22
@jerqi jerqi closed this Aug 8, 2024
@jerqi jerqi reopened this Aug 8, 2024
@jerqi jerqi force-pushed the ISSUE-4236 branch 4 times, most recently from 3949efc to d967218 Compare August 8, 2024 11:37
@@ -33,6 +33,17 @@ public class SecurableObjects {

private static final Splitter DOT_SPLITTER = Splitter.on('.');

/**
* Create the metalake {@link SecurableObject} with the given metalake name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the given metalake name and privileges?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I can change it.

import org.apache.gravitino.utils.PrincipalUtils;

/**
* {@code AccessControlHookDispatcher} is a decorator for {@link AccessControlDispatcher} that not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the meaning of decorator in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can refer to decorator design pattern.

* only delegates access control operations to the underlying access control dispatcher but also
* executes some hook operations before or after the underlying operations.
*/
public class AccessControlHookDispatcher implements AccessControlDispatcher {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get why do we name it Hook here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class provide the hook operations for every dispatcher.

Comment on lines 361 to +364
this.catalogManager = new CatalogManager(config, entityStore, idGenerator);
CatalogHookDispatcher catalogHookDispatcher = new CatalogHookDispatcher(catalogManager);
CatalogNormalizeDispatcher catalogNormalizeDispatcher =
new CatalogNormalizeDispatcher(installDispatcherHooks((CatalogDispatcher) catalogManager));
new CatalogNormalizeDispatcher(catalogHookDispatcher);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we have wrapped the dispatcher too many times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known issues. But we don't have better solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can put normalizeDispatcher to HookDispatcher in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also feel the current Dispatcher mechanism inelegant.
I create a issue track it

@jerqi jerqi closed this Aug 8, 2024
@jerqi jerqi reopened this Aug 8, 2024
@xunliu xunliu changed the title [#4236][FOLLOWUP] feat(core): Rework of post hook for dispatcher [#4236] feat(core): Rework of post hook for dispatcher Aug 8, 2024
Copy link
Member

@xunliu xunliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
If no more comments, I will merge this PR.

@xunliu xunliu merged commit cfbecfd into apache:main Aug 8, 2024
57 of 69 checks passed
@jerryshao
Copy link
Contributor

I don't like the current package name "hook", it doesn't have any meaning. Besides, the changes are related to authorization, why don't you move to authorization?

Anyway, please refactor this code.

xunliu added a commit to xunliu/gravitino that referenced this pull request Aug 9, 2024
@jerqi
Copy link
Contributor Author

jerqi commented Aug 9, 2024

I don't like the current package name "hook", it doesn't have any meaning. Besides, the changes are related to authorization, why don't you move to authorization?

Anyway, please refactor this code.

Normalizing the names may be a pre-hook. I plan to add some authorization unrelated hooks to this class to reduce the number of dispatcher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Add PostHook menchinism for managers
4 participants